/* eslint-disable */
export default {
	initApi(callback) {
		document.addEventListener('WinJSBridgeReady', function () {
			callback();
		});
	},
	login(callback) {
		if (window.WinJSBridge) {
			window.WinJSBridge.call('login', 'openLogin', (res) => {
				callback(res)
			});
		}
	},
	isLogin(callback) {
		if (window.WinJSBridge) {
			window.WinJSBridge.call('login', 'isLogin',  (resp) => {
				callback(resp)
			});
		}
	},
	requestAPI(actionName, params, callback) {
		if (window.WinJSBridge) {
			window.WinJSBridge.call('controller', 'requestAPI', {
				actionName: actionName,
				params: params
			}, function (resp) {
				callback(resp)
			});
		}
	},
	deviceInfo(callback) {
		if (window.WinJSBridge) {
			window.WinJSBridge.call('device', 'deviceInfo', function (resp) {
				callback(resp)
			});
		}
	},
	jumpNativePage(jumpUrl) {
		if (window.WinJSBridge) {
			window.WinJSBridge.call('controller', 'jumpNativePage', {url: jumpUrl});
		}
	},
    imagePreview(options) {
        if (window.WinJSBridge) {
            window.WinJSBridge.call('controller', 'imagePreview', options);
        }
    },
	jumpTab(index) {
		if (window.WinJSBridge) {
			window.WinJSBridge.call('controller', 'jumpNativePage', {url: 'lingsir://tab/show?index=' + index});
		}
	},
	refreshPage() {
		if (window.WinJSBridge) {
			window.WinJSBridge.call('controller', 'refresh', {pullRefresh: true});
		}
	},
	enableRefresh(flag) {
		if (window.WinJSBridge) {
			window.WinJSBridge.call('controller', 'setPullRefresh', {enable: flag});
		}
	},
	showLoading() {
		if (window.WinJSBridge) {
			window.WinJSBridge.call('controller', 'showLoading', {test: true});
		}
	},
	hideLoading() {
		if (window.WinJSBridge) {
			window.WinJSBridge.call('controller', 'hideLoading', {test: true});
		}
	},
	showAlert(msg, type) {
		if (window.WinJSBridge) {
			window.WinJSBridge.call('notification', 'alert', {message: msg, type: type}, function (resp) {
			});
		}
	},
	/*param type: 0对勾 1错误 2感叹号 3无 */
	showToast(msg, type) {
		if (window.WinJSBridge) {
			window.WinJSBridge.call('notification', 'toast', {message: msg, type: type});
		}
	},
	getToken(callback) {
		if (window.WinJSBridge) {
			window.WinJSBridge.call('message', 'obtainUserToken', (res) => {
				callback(res)
			});
		}
	},
	/*
	 * @Method：sharePage
	 * @Description：页面分享
	 * @param params：title：标题，desc：描述，imgUrl: 图片, link：链接
	 */
	sharePage(params) {
		if (window.WinJSBridge) {
			window.WinJSBridge.call('share', 'share', params);
		}
	},
	/*
	 * @Method：showOptionMenu
	 * @Description：显示右上角按钮
	 * @param options：title：优先显示文字，icon：显示icon，onclick：点击回调的js方法
	 */
	showOptionMenu(options, callback) {
		if (window.WinJSBridge) {
			window.WinJSBridge.call('controller', 'showOptionMenu', options, (res) => {
				callback(res)
			});
		}
	},
	/*
	 * 功能描述：购物车插件
	 * @params[handleName]：getCount、getItemCount、addItem、reduceItem、deleteItem
	 * @params[shopId]：店铺id
	 * @params[itemId]：skuId
	 * @params[count]：添加数量
	 * App最低版本要求：2.3.8
	 */
	shopcart(handleName, params, callback) {
		if (window.WinJSBridge) {
			window.WinJSBridge.call('shopcart', handleName, params, function (resp) {
				callback(resp);
			});
		}
	},
	/*
	显示评论列表
	@param url:评论列表页路径
	*/
	openPage(url) {
		if (window.WinJSBridge) {
			window.WinJSBridge.call('controller', 'openPage', {url: url});
		}
	},
}
